package dbTools.tableInfo.field;

import java.util.List;
import java.util.regex.Pattern;

import dbTools.factory.SimpleFactory;
import dbTools.tableInfo.field.Config.IMEType;
import dbTools.tableInfo.field.dataType.IDataType;
import dbTools.tableInfo.field.fieldInfo.FieldInfo;
import dbTools.tableInfo.field.fieldValidator.FieldValidator;

public abstract class Field {

	public static final String TYPE_DATE = "java.util.Date";
	public static final String TYPE_STRING = "java.lang.String";
	public static final String TYPE_LONG = "java.lang.Long";
	
	private final String FLAG_STR = "○";

	public Field(String varNum, 
			String varKey, 
			String varItemName,
			String varFiledName, 
			String varDataType, 
			String varChar, 
			String varLenght, 
			String varCon, 
			String varNotNull, 
			String varDefault, 
			String varMin, 
			String varMax) {
		super();
		
		this.fieldName = varFiledName==null?null:varFiledName.trim();
		if(this.fieldName!=null&& Pattern.matches("[a-z]", this.fieldName.substring(1,2)))
		{
			this.fieldName=this.fieldName.substring(0,1).toLowerCase()+ this.fieldName.substring(1);
		}
		this.itemName = varItemName==null?null:varItemName.trim();
		this.dbDataType = varDataType;
		this.defaultValue = varDefault;
		this.isKey=varKey.equals(FLAG_STR);
		this.isNotNull=varNotNull.equals(FLAG_STR);
		this.maxValue=varMax;
		this.minValue=varMin;
		if(varLenght!=null&&varLenght.length()>0){
			this.lengh=Integer.parseInt(varLenght.split(",")[0]);
		}
		
		this.imeType=SimpleFactory.getIMEType(varChar);
		
		this.fieldInfo= new FieldInfo(varCon);
		
		this.checkers=SimpleFactory.getFieldValidators(this);
	}

	public boolean isKey() {
		return isKey;
	}

	public void setKey(boolean isKey) {
		this.isKey = isKey;
	}

	protected boolean isKey;

	protected String fieldName;

	protected String itemName;

	protected IDataType dataType;

	protected IMEType imeType;

	protected String defaultValue;

	protected boolean isNotNull;

	protected String maxValue;

	protected String minValue;

	protected int lengh;

	protected List<FieldValidator> checkers;

	protected FieldInfo fieldInfo;
	
	protected String dataTypeString;
	
	/** DB数据类型 */
	protected String dbDataType;
	

	public String getDataTypeString() {
		return dataTypeString;
	}

	public void setDataTypeString(String dataTypeString) {
		this.dataTypeString = dataTypeString;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getItemName() {
		return itemName;
	}

	public void setItemName(String itemName) {
		this.itemName = itemName;
	}

	public IDataType getDataType() {
		return dataType;
	}

	public void setDataType(IDataType dataType) {
		this.dataType = dataType;
	}

	public IMEType getImeType() {
		return imeType;
	}

	public void setImeType(IMEType imeType) {
		this.imeType = imeType;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public boolean isNotNull() {
		return isNotNull;
	}

	public void setNotNull(boolean isNotNull) {
		this.isNotNull = isNotNull;
	}

	public String getMaxValue() {
		return maxValue;
	}

	public void setMaxValue(String maxValue) {
		this.maxValue = maxValue;
	}

	public String getMinValue() {
		return minValue;
	}

	public void setMinValue(String minValue) {
		this.minValue = minValue;
	}

	public int getLengh() {
		return lengh;
	}

	public void setLengh(int lengh) {
		this.lengh = lengh;
	}

	public List<FieldValidator> getCheckers() {
		return checkers;
	}

	public void setCheckers(List<FieldValidator> checkers) {
		this.checkers = checkers;
	}

	public FieldInfo getFieldInfo() {
		return fieldInfo;
	}

	public void setFieldInfo(FieldInfo fieldInfo) {
		this.fieldInfo = fieldInfo;
	}

	/**
	 * 获取 dbDataType
	 * @return dbDataType
	 */
	public String getDbDataType() {
		return dbDataType;
	}

	/**
	 * 设定 dbDataType
	 * @param dbDataType  dbDataType
	 */
	public void setDbDataType(String dbDataType) {
		this.dbDataType = dbDataType;
	}

	
}
